package com.changdu.seatunnel.admin.config.converts;

import java.io.IOException;
import java.lang.reflect.Type;

import org.springframework.http.HttpOutputMessage;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;

public class StringOrMappingJackson2HttpMessageConverter extends MappingJackson2HttpMessageConverter {

    private static final StringHttpMessageConverter STRING_HTTP_MSG_CONVERTER = new StringHttpMessageConverter();

    @Override
    protected void writeInternal(Object object, Type type, HttpOutputMessage outputMessage)
            throws IOException, HttpMessageNotWritableException {
        if (object instanceof String) {
            outputMessage.getHeaders().setContentType(MediaType.TEXT_PLAIN);
            STRING_HTTP_MSG_CONVERTER.write((String) object, MediaType.TEXT_PLAIN, outputMessage);
            return;
        }
        super.writeInternal(object, type, outputMessage);
    }
	
}
